/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bungabungaball;

import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.FixtureDef;
import org.jbox2d.dynamics.World;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;

/**
 * An Object on the field.
 *
 * @author Ingo Klose, Stephan Meyer, Sebastian Lehmann
 * @version 1.0
 */
public abstract class GameObject {

    /**
     * Position X
     */
    public int x;
    /**
     * Position Y
     */
    public int y;
    /**
     * The Image of the Object
     */
    public Image image;
    /**
     * The physicle body definition
     */
    protected BodyDef bodyDef;
    /**
     * the physicle shape
     */
    protected Shape shape;
    /**
     * the physicle fixture
     */
    protected FixtureDef fd;
    /**
     * the physicle world
     */
    protected World world;
    /**
     * the physicle body
     */
    protected Body body;

    /**
     * Draw the game object
     *
     * @param g
     */
    public abstract void draw(Graphics g);

    /**
     * Constructor
     *
     * @param x
     * @param y
     * @param image
     * @param w
     */
    public GameObject(int x, int y, Image image, World w) {
        this(x, y, w);
        this.image = image;

        bodyDef = new BodyDef();
        bodyDef.position.set(x / GlobalSettings.jBox2dFactor, y / GlobalSettings.jBox2dFactor);
        bodyDef.type = BodyType.DYNAMIC;
    }

    /**
     * Constructor
     *
     * @param x
     * @param y
     * @param image
     */
    public GameObject(int x, int y, Image image) {
        this.x = x;
        this.y = y;
        this.image = image;

        bodyDef = new BodyDef();
        bodyDef.position.set(x / GlobalSettings.jBox2dFactor, y / GlobalSettings.jBox2dFactor);
        bodyDef.type = BodyType.DYNAMIC;
    }

    /**
     * Constructor
     *
     * @param x
     * @param y
     * @param w
     */
    public GameObject(int x, int y, World w) {
        this.x = x;
        this.y = y;
        this.world = w;

        bodyDef = new BodyDef();
        bodyDef.position.set(x / GlobalSettings.jBox2dFactor, y / GlobalSettings.jBox2dFactor);
        bodyDef.type = BodyType.DYNAMIC;
    }

    /**
     * Constructor
     *
     * @param x
     * @param y
     */
    public GameObject(int x, int y) {
        this.x = x;
        this.y = y;

        bodyDef = new BodyDef();
        bodyDef.position.set(x / GlobalSettings.jBox2dFactor, y / GlobalSettings.jBox2dFactor);
        bodyDef.type = BodyType.DYNAMIC;
    }

    /**
     * Constructor
     *
     * @param image
     * @param w
     */
    public GameObject(Image image, World w) {
        this.image = image;
        this.world = w;

        bodyDef = new BodyDef();
        bodyDef.type = BodyType.DYNAMIC;
    }

    /**
     * Constructor
     *
     * @param image
     */
    public GameObject(Image image) {
        this.image = image;

        bodyDef = new BodyDef();
        bodyDef.type = BodyType.DYNAMIC;
    }

    /**
     * Constructor
     *
     * @param w
     */
    public GameObject(World w) {
        this.world = w;

        bodyDef = new BodyDef();
        bodyDef.type = BodyType.DYNAMIC;
    }

    /**
     * Constructor
     */
    public GameObject() {
        bodyDef = new BodyDef();
        bodyDef.type = BodyType.DYNAMIC;
    }

    /**
     * Get the Position x
     *
     * @return int
     */
    public int getX() {
        return x;
    }

    /**
     * Set the Position x
     *
     * @param x
     */
    public void setX(int x) {
        this.x = x;
        bodyDef.position.set(x / GlobalSettings.jBox2dFactor, bodyDef.position.y);
    }

    /**
     * Get the Position y
     *
     * @return Position y
     */
    public int getY() {
        return y;
    }

    /**
     * Set the Position Y
     *
     * @param y
     */
    public void setY(int y) {
        this.y = y;
        bodyDef.position.set(bodyDef.position.x, y / GlobalSettings.jBox2dFactor);
    }

    /**
     * Rotate the Object
     *
     * @param r
     */
    public void rotate(float r) {
        image.rotate(r);
    }

    /**
     * Get the object rotation
     *
     * @return object rotation
     */
    public float getRotation() {
        return image.getRotation();
    }

    /**
     * Set the rotation
     *
     * @param r
     */
    public void setRotation(float r) {
        image.setRotation(r);
    }

    /**
     * Set the body of the game object
     *
     * @param b
     */
    public void setBody(Body b) {
        body = b;
    }

    /**
     * get the physicle body
     *
     * @return physicle body
     */
    public Body getBody() {
        return body;
    }

    /**
     * get the physicle body definition
     *
     * @return physicle body definition
     */
    public BodyDef getBodyDef() {
        return bodyDef;
    }

    /**
     * get the physicle fixture def
     *
     * @return physicle fixture def
     */
    public FixtureDef getFixtureDef() {
        return fd;
    }
}
